package com.sam;

import java.sql.*;

public class MyConnection {
	Connection conn;
	Statement stmt;
	String driverStr="", urlStr="", useridStr="",passwordStr="";
	
	public MyConnection (){
	}
	
	public MyConnection (String DB){
		
		System.out.println(DB.toUpperCase());
		switch (DB.toUpperCase()) {
		case "MSSQL" : 
			useridStr="sa";
			passwordStr="111";
			driverStr="com.microsoft.sqlserver.jdbc.SQLServerDriver";
			urlStr="jdbc:sqlserver://127.0.0.1:1433;databaseName=CH06範例資料庫";
			break;
		case "MYSQL" : 
			useridStr="j102u17";
			passwordStr="j102u17.989";
			driverStr="com.mysql.jdbc.Driver";
			urlStr="jdbc:mysql://j.snpy.org:3306/j102u17";
			break;
		case "ORACLE" : 
			driverStr="oracle.jdbc.OracleDriver";
			urlStr="";
			break;
		}
		System.out.println(urlStr);
		try {
			Class.forName(driverStr);
			//conn=DriverManager.getConnection(urlStr);
			conn=DriverManager.getConnection(urlStr, useridStr, passwordStr); 
			System.out.println("conn = " + conn);
			stmt=conn.createStatement();			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}		
	}	

	public Connection getMyConn(){
	   return conn;	
	}
	
	public Statement getMyStatement(){
	   return stmt;
	}
	
}
